/***
 * * PROJECT
 * *    Logical Neighborhood Routing
 * * VERSION
 * *    $Revision: 1.2 $
 * * DATE
 * *    $Date: 2007/02/02 11:24:00 $
 * * LOG
 * *    $Log: TestSwansEstimator.java,v $
 * *    Revision 1.2  2007/02/02 11:24:00  lmottola
 * *    Benchmarking code for compiler in.
 * *
 * *    Revision 1.1  2007/01/04 09:22:42  lmottola
 * *    Changed getEstimation signature in Estimator interface.
 * *
 * *
 * *   Logical Neighborhoods Routing - Java Version
 * *
 * *   This program is free software; you can redistribute it and/or
 * *   modify it under the terms of the GNU General Public License
 * *   as published by the Free Software Foundation; either version 2
 * *   of the License, or (at your option) any later version.
 * *
 * *   This program is distributed in the hope that it will be useful,
 * *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * *   GNU General Public License for more details.
 * *
 * *   You should have received a copy of the GNU General Public License
 * *   along with this program; if not, you may find a copy at the FSF web
 * *   site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
 * *   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * *   Boston, MA  02111-1307, USA
 ***/
package atag.runtime.ln.estimation;

import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

import atag.apps.traffic.IDConstants;
import atag.apps.traffic.StartSwansSim;
import atag.apps.traffic.TrafficTopologyGenerator;
import atag.common.ATaGProgram;
import atag.common.NetworkTopology;
import atag.compiler.Estimator;
import atag.runtime.NodeInfo;
import atag.runtime.NodeLocation;
import atag.runtime.ln.nodeAttributes.IntegerAttribute;
import atag.runtime.ln.nodeAttributes.SetAttribute;
import atag.runtime.platformDependent.JiSTClock;

/**
 * @author Luca Mottola <a
 *         href="mailto:mottola@elet.polimi.it">mottola@elet.polimi.it</a>
 * 
 */
public class TestSwansEstimator {

	/**
	 * Starts the Swans-based estimator using the pre-built traffic application.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		int nextNodeId = 0;
		Vector attributes, assignedTasks;
		Set<NodeInfo> nodes = new HashSet<NodeInfo>();

		// Create a speed sampler
		attributes = new Vector();
		attributes.add(new IntegerAttribute("HS", 0));
		assignedTasks = new Vector();
		assignedTasks.add(new Integer(IDConstants.T_SPEEDSAMPLER));
		assignedTasks.add(new Integer(IDConstants.T_AQLENCALCULATOR));
		NodeInfo typeSpeedSampler = new NodeInfo(nextNodeId++,
				new NodeLocation(0, 0), attributes, 1, assignedTasks,
				new JiSTClock());
		nodes.add(typeSpeedSampler);

		// Create a ramp sampler
		attributes = new Vector();
		attributes.add(new IntegerAttribute("HS", 0));
		assignedTasks = new Vector();
		assignedTasks.add(new Integer(IDConstants.T_RAMPSAMPLER));
		assignedTasks.add(new Integer(IDConstants.T_ASCALCULATOR));
		NodeInfo typeRampSampler = new NodeInfo(nextNodeId++, new NodeLocation(
				400, 0), attributes, 1, assignedTasks, new JiSTClock());
		nodes.add(typeRampSampler);

		// Creating the SpeedLimitDisplayer
		attributes = new Vector();
		attributes.add(new IntegerAttribute("HS", 0));
		attributes.add(new SetAttribute("attachedActuators",
				new String[] { "SpeedLimitDisplayer" }));
		assignedTasks = new Vector();
		assignedTasks.add(new Integer(IDConstants.T_SLDISPLAYER));
		assignedTasks.add(new Integer(IDConstants.T_RGSCALCULATOR));
		NodeInfo typeLimitDisplayer = new NodeInfo(nextNodeId++,
				new NodeLocation(400, 0), attributes, 1, assignedTasks,
				new JiSTClock());
		nodes.add(typeLimitDisplayer);

		// Creating the RGSignalDisplayer
		attributes = new Vector();
		attributes.add(new IntegerAttribute("HS", 0));
		attributes.add(new SetAttribute("attachedActuators",
				new String[] { "RGSignalDisplayer" }));
		assignedTasks = new Vector();
		assignedTasks.add(new Integer(IDConstants.T_RGSDISPLAYER));
		assignedTasks.add(new Integer(IDConstants.T_SLCALCULATOR));
		NodeInfo typeRGDisplayer = new NodeInfo(nextNodeId++, new NodeLocation(
				400, 400), attributes, 1, assignedTasks, new JiSTClock());
		nodes.add(typeRGDisplayer);

		NetworkTopology topology = new NetworkTopology(nodes,
				TrafficTopologyGenerator.COMM_RANGE, 0, 1000, 1000);
		ATaGProgram atagPrg = StartSwansSim.returnTrafficApplication();
		atagPrg.sanitize();

		System.out.println("Starting Swans estimator...");
		Estimator estimator = new LNSwansEstimator(topology,
				atag.apps.traffic.PreBuiltAtagManager.class, atagPrg, 1000,
				9999999);
		estimator.getCostEstimate(null);
	}
}
